set more off

capture log close
log using output_final.log, replace

use dataset_final.dta, clear


*create country dummy variables

quietly tabulate id, gen(dum_country)

*create year dummy variables

quietly tabulate year, gen(dum_year)

*calculate the population of the old

gen av_age65over=av_age_65_69+ av_age_70_74+ av_age_75_79+ av_age_80_84+ av_age_85over
gen av_age2064=av_age_20_24+ av_age_25_29+ av_age_30_34+ av_age_35_39+ av_age_40_44 +av_age_45_49+ av_age_50_54+ av_age_55_59+ av_age_60_64
gen av_age019=av_age_0_4+ av_age_5_9+ av_age_10_14+ av_age_15_19
gen av_age014=av_age_0_4+ av_age_5_9+ av_age_10_14


*define the population share of the old

gen av_oldage_ratio = av_age65over/av_pop_total

gen av_depend = av_age65over/av_age2064 

gen av_midage_ratio = av_age2064/av_pop_total
gen av_yongage_ratio = av_age019/av_pop_total


*create a dummy for EU countries
gen dum_eu =1 if id==1 | id==2 | id==3 |id==6| id==7| id==8|id==9 |id==10 |id== 11| id==12| id==13| id==15 | id==17 |id==20| id==22| id==25|id==26 |id== 27| id==28| id==29| id ==30 |id==33
replace dum_eu=0 if dum_eu==.

*create a dummy for developed countries
gen dum_developed = 1  if id==1 | id==2 | id==3 |id==4|id==6| id==7|id==9 |id==10 | id== 11| id==13| id==14 |id==15 | id==17 |id==18|id==20| id==22|id==23|id==24|id==26 |id== 29| id==30| id==31| id==33|id==34
replace dum_developed=0 if dum_developed==.


*define net private social expenditure
gen av_net_priv_socialexp= av_net_total_socialexp - av_net_public_socialexp

*define the share of net public expenditure in net total expenditure
gen av_net_pub_ratio = av_net_public_socialexp/av_net_total_socialexp

*define the share of net private expenditure in net total expenditure
gen av_net_priv_ratio = av_net_priv_socialexp/ av_net_total_socialexp

*define the cross term between the ratios of net private and net public social
*expenditure
gen cross_net_pub_priv = av_net_pub_ratio*av_net_priv_ratio

*rename the variables to simplify notations
gen oldage = av_oldage_ratio
gen depend = av_depend * 100
gen midage = av_midage_ratio
gen youngage = av_yongage_ratio
gen unemp = av_unemployment_rate
gen grosspub = av_socialexp_pub


*modified by factor price
gen nettotal = av_nettotal_factorcost
gen netpub = av_netpub_factorcost
gen netpriv = nettotal - netpub

gen netpub_ratio = netpub/(netpub + netpriv)
gen netpriv_ratio = netpriv/(netpub + netpriv)
gen pubpriv = netpub * netpriv
gen growth = av_gdp_growth
gen pubpriv_ratio = netpriv/netpub
gen pubpriv_total = pubpriv_ratio * nettotal

gen ineq8020 = av_s80_s20
gen ineq9010 = av_p90_p10


gen gini_after = av_gini_index*100
gen gini_before = av_gini_index_bt

gen gini_diff = gini_before - gini_after

gen gdp = av_gdp_vol


*definition of gdp per head
gen gdpph = av_gdp_volppp/(1000*av_pop_total)

*define a dummy variable for beveridgean countries: australia, canada, denmark,
* ireland, japan, netherland, newzealand, swizerland, uk, usa
gen dum_bev = 1 if id== 1|id==4 | id==7| id==15 | id==18 | id==22| id==23 |id==31 | id==33 | id==34
replace dum_bev =0 if dum_bev==.

*define a dummy variable for bismarckian countries: austria, belgium, france,
* germany, greece, italy, spain
gen dum_bis = 1 if id ==2 | id==3 | id==10 | id==11 |id ==12| id==17 | id==29
replace dum_bis = 0 if dum_bis ==.

*define a dummy variable for countries included in the data by caminada and
*gouswaard(2005): austria, belgium, canada, czech, denmark, germany, finland,
*ireland, italy, japna, korea, norway, netherland, newzealand, sweden, uk, usa
gen dum_cg2005 = 1 if id==2|id==3|id==4|id==6|id==7|id==9|id==11|id==15|id==17|id==18|id==19|id==22|id==23|id==24|id==30|id==33|id==34

* define the sample of countries without spain
. gen dum_gc2009 = 1 if id == 1 |id==2|id==3|id==4|id==6|id==7|id==9|id==10|id==11|id==14|id==15|id==17|id==18|id==19|id==20|id==22|id==23|id==24|id==25|id==26|id==27|id==30|id==31|id==33|id==34
. replace dum_gc2009 =0  if dum_gc2009 ==.


* create a dummy variable combining dum_developed and dum_gc2009
gen dum_comb = 1 if dum_developed ==1 & dum_gc2009 ==1
replace dum_comb=0 if dum_comb ==.

*creat a dummy variable adding Spain (id =29) to gc2009
gen dum_withspain = 1 if id == 1 |id==2|id==3|id==4|id==6|id==7|id==9|id==10|id==11|id==14|id==15|id==17|id==18|id==19|id==20|id==22|id==23|id==24|id==25|id==26|id==27|id==29|id==30|id==31|id==33|id==34
replace dum_withspain = 0 if dum_withspain ==.

*create a country dummy with Spain added to and Korea deleted from gc2009
gen dum_gc2009_rev2 = 1 if id == 1 |id==2|id==3|id==4|id==6|id==7|id==9|id==10|id==11|id==14|id==15|id==17|id==18|id==20|id==22|id==23|id==24|id==25|id==26|id==27|id==29|id==30|id==31|id==33|id==34
replace dum_gc2009_rev2 = 0 if dum_gc2009_rev2 ==.

*substitute gdpph for gdp in all what follows
drop gdp
gen gdp = gdpph


***** Table2 ******  
*summary statistics tex output, with spain
sutex gini_after ineq8020 ineq9010 netpub netpriv nettotal pubpriv_ratio depend unemp gdp if dum_withspain ==1 & year >=1990, lab nobs key(descstat) replace file(descstat_rev.tex) title("Summary statistics") minmax 



* create time variable
gen time=(year-1990)/5 if year >= 1990

*time dummy
quietly tabulate time, gen(dum_time)

**********************************************
*preliminary fixed effect analysis with netput netpriv pubpriv (contorl: depend)
*use sample without spain, without controling gdp

xtset id year

 
***** Table3 *****
*(without pubpriv netpriv is significant but with it netpriv is insignificant and pubpriv is significant.)
xtreg gini_after netpub netpriv depend unemp dum_time2 dum_time4  if dum_gc2009 ==1 & year >=1990, fe vce(robust)
xtreg gini_after netpub netpriv pubpriv depend unemp dum_time2 dum_time4  if dum_gc2009 ==1 & year >=1990, fe vce(robust)

*preliminary fixed effect analysis with ineq8020
*(Without pubpriv, netpriv is insignificant but with it both netprive and pubpriv are significant.)
xtreg ineq8020 netpub netpriv depend unemp dum_time2 dum_time4 if dum_gc2009 ==1 & year >=1990, fe vce(robust)
xtreg ineq8020 netpub netpriv pubpriv depend unemp dum_time2 dum_time4 if dum_gc2009 ==1 & year >=1990, fe vce(robust)


*preliminary fixed effect analysis with ineq9010
*(without pubpriv, netpriv is insignificant but with it both netpriv and pubpriv are significant)
xtreg ineq9010 netpub netpriv depend unemp dum_time2 dum_time4 if dum_gc2009 ==1 & year >=1990, fe vce(robust)
xtreg ineq9010 netpub netpriv pubpriv depend unemp dum_time2 dum_time4 if dum_gc2009 ==1 & year >=1990, fe vce(robust)


*output in tex
xtreg gini_after netpub netpriv depend unemp dum_time2 dum_time4  if dum_gc2009 ==1 & year >=1990, fe vce(robust)
est sto gini_gc
xtreg gini_after netpub netpriv pubpriv depend unemp dum_time2 dum_time4  if dum_gc2009 ==1 & year >=1990, fe vce(robust)
est sto gini_cross
xtreg ineq8020 netpub netpriv depend unemp dum_time2 dum_time4 if dum_gc2009 ==1 & year >=1990, fe vce(robust)
est sto ineq8020_gc
xtreg ineq8020 netpub netpriv pubpriv depend unemp dum_time2 dum_time4 if dum_gc2009 ==1 & year >=1990, fe vce(robust)
est sto ineq8020_cross
xtreg ineq9010 netpub netpriv depend unemp dum_time2 dum_time4 if dum_gc2009 ==1 & year >=1990, fe vce(robust)
est sto ineq9010_gc
xtreg ineq9010 netpub netpriv pubpriv depend unemp dum_time2 dum_time4 if dum_gc2009 ==1 & year >=1990, fe vce(robust)
est sto ineq9010_cross

esttab gini_gc gini_cross ineq8020_gc ineq8020_cross ineq9010_gc ineq9010_cross using xtreg_gccross.tex, replace se b(4) r2 star(* 0.1 ** 0.05 *** 0.01) title(Preliminary Regression Analysis) nodepvar booktabs alignment(D{.}{.}{-1}) coeflabels(netpub "$\mathit{NetPub}$" netpriv "$\mathit{NetPriv}$" pubpriv "$\mathit{NetPub}\times\mathit{NetPriv}$" depend "$\mathit{Depend}$" unemp "$\mathit{Unemp}$" dum_time2 "$\mu_2$" dum_time4 "$\mu_4$" _cons "$\mathit{C}$") keep(netpub netpriv pubpriv depend unemp dum_time2 dum_time4 _cons) nodepvar 


************************************************

*use sample with spain in all what follows
drop dum_gc2009
gen dum_gc2009 = dum_withspain

************************************************


***** Footnote 16 *****
*output in tex
xtreg gini_after netpub netpriv depend unemp gdp  dum_time4  if dum_gc2009 ==1 & year >=1990, fe vce(robust)
est sto gini_gc
xtreg gini_after netpub netpriv pubpriv depend unemp gdp  dum_time4  if dum_gc2009 ==1 & year >=1990, fe vce(robust)
est sto gini_cross
xtreg ineq8020 netpub netpriv depend unemp gdp  dum_time4 if dum_gc2009 ==1 & year >=1990, fe vce(robust)
est sto ineq8020_gc
xtreg ineq8020 netpub netpriv pubpriv depend unemp gdp  dum_time4 if dum_gc2009 ==1 & year >=1990, fe vce(robust)
est sto ineq8020_cross
xtreg ineq9010 netpub netpriv depend unemp gdp dum_time4 if dum_gc2009 ==1 & year >=1990, fe vce(robust)
est sto ineq9010_gc
xtreg ineq9010 netpub netpriv pubpriv depend gdp unemp dum_time4 if dum_gc2009 ==1 & year >=1990, fe vce(robust)
est sto ineq9010_cross

esttab gini_gc gini_cross ineq8020_gc ineq8020_cross ineq9010_gc ineq9010_cross using xtreg_gccross_rev2.tex, replace se b(4) r2 star(* 0.1 ** 0.05 *** 0.01) title(Preliminary Regression Analysis) nodepvar booktabs alignment(D{.}{.}{-1}) coeflabels(netpub "$\mathit{NetPub}$" netpriv "$\mathit{NetPriv}$" pubpriv "$\mathit{NetPub}\times\mathit{NetPriv}$" depend "$\mathit{Depend}$" unemp "$\mathit{Unemp}$" gdp "$\mathit{GDPph}$" dum_time4 "$\mu_4$" _cons "$\mathit{C}$") keep(netpub netpriv pubpriv depend unemp gdp dum_time4 _cons) nodepvar 


*fixed effect analysis with gini

xtset id year


***** Table 4: Fixed Effect *****
*(pubpriv_ratio is not significant)
xtreg gini_after nettotal pubpriv_ratio pubpriv_total depend unemp gdp if dum_gc2009 ==1 & year >=1990, fe vce(robust)
est sto gini_total_0
xtreg gini_after nettotal pubpriv_ratio pubpriv_total depend unemp gdp dum_time2 if dum_gc2009 ==1 & year >=1990, fe vce(robust)
est sto gini_total_2
xtreg gini_after nettotal pubpriv_ratio pubpriv_total depend unemp gdp dum_time4 if dum_gc2009 ==1 & year >=1990, fe vce(robust)
est sto gini_total_4
xtreg gini_after nettotal pubpriv_ratio pubpriv_total depend unemp gdp dum_time2 dum_time4 if dum_gc2009 ==1 & year >=1990, fe vce(robust)
est sto gini_total_24
*output in tex
esttab gini_total_0 gini_total_2 gini_total_4 gini_total_24 using fixed_gini.tex, replace se b(4) r2 star(* 0.1 ** 0.05 *** 0.01) title(Impacts on $\mathit{Gini}$:Fixed Effect) nodepvar booktabs alignment(D{.}{.}{-1}) coeflabels(nettotal "$\mathit{NetTotal}$" pubpriv_ratio "$\mathit{PrivPubRatio}$" pubpriv_total "$\mathit{PrivPubRatio}\times\mathit{NetTotal}$" depend "$\mathit{Depend}$" unemp "$\mathit{Unemp}$" gdp "$\mathit{GDPph}$" dum_time2 "$\mu_2$" dum_time4 "$\mu_4$" _cons "$\mathit{C}$") keep(nettotal pubpriv_ratio pubpriv_total depend unemp gdp dum_time2 dum_time4 _cons) nodepvar 




*dynamic panel analysis with gini
*redifine time
drop time

gen time=(year-1945)/5

*dynamic panel

xtset id time


***** Table4: Dynamic Panel ***** 
xtdpdsys gini_after depend unemp gdp if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total) vce(robust) artests(3)
est sto sys_gini_nodum
estat abond
xtdpdsys gini_after depend unemp gdp dum_time2 if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total) vce(robust) artests(3)
est sto sys_gini_dum2
estat abond
xtdpdsys gini_after depend unemp gdp dum_time4 if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total) vce(robust) artests(3)
est sto sys_gini_dum4
estat abond
xtdpdsys gini_after depend unemp gdp dum_time2 dum_time4 if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total) vce(robust) artests(3)
est sto sys_gini_dum24
estat abond

*output in tex
esttab sys_gini_nodum sys_gini_dum2 sys_gini_dum4 sys_gini_dum24 using sys_gini.tex, replace se b(4) r2 star(* 0.1 ** 0.05 *** 0.01) title(Impacts on $\mathit{Gini}$: Dynamic Panel) nodepvar booktabs alignment(D{.}{.}{-1}) coeflabels(lags(1) "$\mathit{Gini}_{t-1}$" nettotal "$\mathit{NetTotal}$" pubpriv_ratio "$\mathit{PrivPubRatio}$" pubpriv_total "$\mathit{PrivPubRatio}\times\mathit{NetTotal}$" depend "$\mathit{Depend}$" unemp "$\mathit{Unemp}$" gdp "$\mathit{GDPph}$" dum_time2 "$\mu_2$" dum_time4 "$\mu_4$" _cons "$\mathit{C}$") keep( nettotal pubpriv_ratio pubpriv_total depend unemp gdp dum_time2 dum_time4 _cons) nodepvar 

*Sargan test
xtdpdsys gini_after depend unemp gdp if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total)  artests(3)
estat sargan
xtdpdsys gini_after depend unemp gdp dum_time2 if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total)  artests(3)
estat sargan
xtdpdsys gini_after depend unemp gdp dum_time4 if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total)  artests(3)
estat sargan
xtdpdsys gini_after depend unemp gdp dum_time2 dum_time4 if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total)  artests(3)
estat sargan



*define totaleffect, including dum_time4
xtdpdsys gini_after depend unemp gdp dum_time4 if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total) vce(robust) artests(3)
gen totaleffect_gini_dynm4 = _b[nettotal]*nettotal + _b[pubpriv_total]*pubpriv_total


***** Table 7 :Gini *****
*interval estimation in effect of total social protection system
*(totaleffect_gini = 0 or not）

*all countries
forval i = 1(1)34{
gen a1=nettotal if id==`i' & year==2010
replace a1=0 if a1==.
gen a2=pubpriv_total if id==`i' & year==2010
replace a2=0 if a2==.
gen a3=pubpriv_ratio if id ==`i' & year==2010
replace a3=0 if a3==.
quietly summarize a1
scalar v1=r(max)
quietly summarize a2
scalar v2=r(max)
quietly summarize a3
scalar v3 = r(max)
lincom v1*nettotal + v2*pubpriv_total
display as text "country id" as text `i'
display as text "year" as text 2010
display as text "privpub_ratio" v3
drop a1 a2 a3
}

***** Figure1 and Figure2 ***** 
*plot totaleffect in 2010, dyanamic panel results
twoway  (scatter totaleffect_gini_dynm4 grosspub if dum_gc2009 ==1 & year ==2010, mlabel(id) mlabposition(7)), ytitle(Total Impact on Gini) xtitle(Gross Public Expenditure (%))
graph export "totaleffect_gini_dym_grosspub_rev.eps", as(eps) replace
twoway (scatter totaleffect_gini_dynm4 pubpriv_ratio if dum_gc2009 ==1 & year ==2010, mlabel(id) mlabposition(7)), ytitle(Total Impact on Gini) xtitle(Net Private SE/Net Public SE )
graph export "totaleffect_gini_dym_pubpriv_rev.eps", as(eps) replace

*******************************************************

*fixed effect analysis with ineq8020


xtset id year

***** Table5: Fixed Effect *****
*fixed effect analysis with ineq8020
*(pubpriv_ratio is not significant)
xtreg ineq8020 nettotal pubpriv_ratio pubpriv_total depend unemp gdp if dum_gc2009 ==1 & year >=1990, fe vce(robust)
est sto ineq8020_total_0
xtreg ineq8020 nettotal pubpriv_ratio pubpriv_total depend unemp gdp dum_time2 if dum_gc2009 ==1 & year >=1990, fe vce(robust)
est sto ineq8020_total_2
xtreg ineq8020 nettotal pubpriv_ratio pubpriv_total depend unemp gdp dum_time4 if dum_gc2009 ==1 & year >=1990, fe vce(robust)
est sto ineq8020_total_4
xtreg ineq8020 nettotal pubpriv_ratio pubpriv_total depend unemp gdp dum_time2 dum_time4 if dum_gc2009 ==1 & year >=1990, fe vce(robust)
est sto ineq8020_total_24
*oupput in tex
esttab ineq8020_total_0 ineq8020_total_2 ineq8020_total_4 ineq8020_total_24 using fixed_ineq8020.tex, replace se b(4) r2 star(* 0.1 ** 0.05 *** 0.01) title(Impacts on $\mathit{Ineq8020}$:Fixed Effect) nodepvar booktabs alignment(D{.}{.}{-1}) coeflabels(nettotal "$\mathit{NetTotal}$" pubpriv_ratio "$\mathit{PrivPubRatio}$" pubpriv_total "$\mathit{PrivPubRatio}\times\mathit{NetTotal}$" depend "$\mathit{Depend}$" unemp "$\mathit{Unemp}$" gdp "$\mathit{GDPph}$" dum_time2 "$\mu_2$" dum_time4 "$\mu_4$" _cons "$\mathit{C}$") keep(nettotal pubpriv_ratio pubpriv_total depend unemp gdp dum_time2 dum_time4 _cons) nodepvar 


***** Table5: Dynamic Panel *****
*dynamic panel analysis with ineq8020
xtset id time

xtdpdsys ineq8020 depend unemp gdp if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total) vce(robust) artests(3)
est sto sys_ineq8020_nodum
estat abond
xtdpdsys ineq8020 depend unemp gdp dum_time2 if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total) vce(robust) artests(3)
est sto sys_ineq8020_dum2
estat abond
xtdpdsys ineq8020 depend unemp gdp dum_time4 if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total) vce(robust) artests(3)
est sto sys_ineq8020_dum4
estat abond
xtdpdsys ineq8020 depend unemp gdp dum_time2 dum_time4 if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total) vce(robust) artests(3)
est sto sys_ineq8020_dum24
estat abond

*output in tex
esttab sys_ineq8020_nodum sys_ineq8020_dum2 sys_ineq8020_dum4 sys_ineq8020_dum24 using sys_ineq8020.tex, replace se b(4) r2 star(* 0.1 ** 0.05 *** 0.01) title(Impacts on $\mathit{Ineq8020}$: Dynamic Panel) nodepvar booktabs alignment(D{.}{.}{-1}) coeflabels(lags(1) "$\mathit{Gini}_{t-1}$" nettotal "$\mathit{NetTotal}$" pubpriv_ratio "$\mathit{PrivPubRatio}$" pubpriv_total "$\mathit{PrivPubRatio}\times\mathit{NetTotal}$" depend "$\mathit{Depend}$" unemp "$\mathit{Unemp}$" gdp "$\mathit{GDPph}$" dum_time2 "$\mu_2$" dum_time4 "$\mu_4$" _cons "$\mathit{C}$") keep( nettotal pubpriv_ratio pubpriv_total depend unemp gdp dum_time2 dum_time4 _cons) nodepvar 


*Sargan test
xtdpdsys ineq8020 depend unemp gdp if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total) artests(3)
estat sargan
xtdpdsys ineq8020 depend unemp gdp dum_time2 if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total)  artests(3)
estat sargan
xtdpdsys ineq8020 depend unemp gdp dum_time4 if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total)  artests(3)
estat sargan
xtdpdsys ineq8020 depend unemp gdp dum_time2 dum_time4 if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total) artests(3)
estat sargan




**define totaleffect, including dum_time4
xtdpdsys ineq8020 depend unemp gdp dum_time4 if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total) vce(robust) artests(3)
gen totaleffect_ineq8020_dynm4 = _b[nettotal]*nettotal + _b[pubpriv_total]*pubpriv_total

***** Table 7 :Ineq8020 *****
*interval estimation in effect of total social protection system
*(totaleffect_gini = 0 or not）

*all countries
forval i = 1(1)34{
gen a1=nettotal if id==`i' & year==2010
replace a1=0 if a1==.
gen a2=pubpriv_total if id==`i' & year==2010
replace a2=0 if a2==.
gen a3=pubpriv_ratio if id ==`i' & year==2010
replace a3=0 if a3==.
quietly summarize a1
scalar v1=r(max)
quietly summarize a2
scalar v2=r(max)
quietly summarize a3
scalar v3 = r(max)
lincom v1*nettotal + v2*pubpriv_total
display as text "country id" as text `i'
display as text "year" as text 2010
display as text "privpub_ratio" v3
drop a1 a2 a3
}



*************************************


***** Table6: Fixed Effect *****
*fixed effect analysis with ineq9010

xtset id year
 
*(pubpriv_ratio is not significant)
xtreg ineq9010 nettotal pubpriv_ratio pubpriv_total depend unemp gdp if dum_gc2009 ==1 & year >=1990, fe vce(robust)
est sto ineq9010_total_0
xtreg ineq9010 nettotal pubpriv_ratio pubpriv_total depend unemp gdp dum_time2 if dum_gc2009 ==1 & year >=1990, fe vce(robust)
est sto ineq9010_total_2
xtreg ineq9010 nettotal pubpriv_ratio pubpriv_total depend unemp gdp dum_time4 if dum_gc2009 ==1 & year >=1990, fe vce(robust)
est sto ineq9010_total_4
xtreg ineq9010 nettotal pubpriv_ratio pubpriv_total depend unemp gdp dum_time2 dum_time4 if dum_gc2009 ==1 & year >=1990, fe vce(robust)
est sto ineq9010_total_24
*output in tex
esttab ineq9010_total_0 ineq9010_total_2 ineq9010_total_4 ineq9010_total_24 using fixed_ineq9010.tex, replace se b(4) r2 star(* 0.1 ** 0.05 *** 0.01) title(Impacts on $\mathit{Ineq9010}$: Fixed effect) nodepvar booktabs alignment(D{.}{.}{-1}) coeflabels(nettotal "$\mathit{NetTotal}$" pubpriv_ratio "$\mathit{PrivPubRatio}$" pubpriv_total "$\mathit{PrivPubRatio}\times\mathit{NetTotal}$" depend "$\mathit{Depend}$" unemp "$\mathit{Unemp}$" gdp "$\mathit{GDPph}$" dum_time2 "$\mu_2$" dum_time4 "$\mu_4$" _cons "$\mathit{C}$") keep(nettotal pubpriv_ratio pubpriv_total depend unemp gdp dum_time2 dum_time4 _cons) nodepvar 



***** Table6: Dynamic Panel *****
*dynamic panel analysis with ineq9010

xtset id time

xtdpdsys ineq9010 depend unemp gdp if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total) vce(robust) artests(3)
est sto sys_ineq9010_nodum
estat abond
xtdpdsys ineq9010 depend unemp gdp dum_time2 if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total) vce(robust) artests(3)
est sto sys_ineq9010_dum2
estat abond
xtdpdsys ineq9010 depend unemp gdp dum_time4 if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total) vce(robust) artests(3)
est sto sys_ineq9010_dum4
estat abond
xtdpdsys ineq9010 depend unemp gdp dum_time2 dum_time4 if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total) vce(robust) artests(3)
est sto sys_ineq9010_dum24
estat abond

*output in tex
esttab sys_ineq9010_nodum sys_ineq9010_dum2 sys_ineq9010_dum4 sys_ineq9010_dum24 using sys_ineq9010.tex, replace se b(4) r2 star(* 0.1 ** 0.05 *** 0.01) title(Impacts on $\mathit{Ineq9010}$: Dynamic Panel) nodepvar booktabs alignment(D{.}{.}{-1}) coeflabels(lags(1) "$\mathit{Gini}_{t-1}$" nettotal "$\mathit{NetTotal}$" pubpriv_ratio "$\mathit{PrivPubRatio}$" pubpriv_total "$\mathit{PrivPubRatio}\times\mathit{NetTotal}$" depend "$\mathit{Ageing}$" unemp "$\mathit{Unemp}$" gdp "$\mathit{GDPph}$" dum_time2 "$\mu_2$" dum_time4 "$\mu_4$" _cons "$\mathit{C}$") keep( nettotal pubpriv_ratio pubpriv_total depend unemp gdp dum_time2 dum_time4 _cons) nodepvar 



*Sargan test
xtdpdsys ineq9010 depend unemp gdp if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total) artests(3)
estat sargan
xtdpdsys ineq9010 depend unemp gdp dum_time2 if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total) artests(3)
estat sargan
xtdpdsys ineq9010 depend unemp gdp dum_time4 if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total) artests(3)
estat sargan
xtdpdsys ineq9010 depend unemp gdp dum_time2 dum_time4 if dum_gc2009 ==1 & year >=1990, lags(1) endogenous(nettotal) endogenous(pubpriv_ratio) endogenous(pubpriv_total) artests(3)
estat sargan



log close

exit
